// pages/device/device.js
import "../../lib/wxPromise/wxPromise.min.js";
import regeneratorRuntime from '../../lib/wxPromise/wxPromise.min.js'
import { tabbar_route_map, linkToTabbar } from "../../utils/route.js";
import api from "../../api/api";
import http from "../../utils/request.js";
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    order: {
      list_order: null,
      list_washmode: null,
      washer: null
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    const token = wx.getStorageSync("token");
    // console.log("options", options);
    // let {
    //   did
    // } = app.globalData
    let did = "B220001";
    if (!did) {
      wx.showModal({
        title: "提示",
        content: "无法识别设备号,请重新扫码识别",
        showCancel: false,
        cancelText: "取消",
        cancelColor: "#000000",
        confirmText: "确定",
        confirmColor: "#3CC51F",
        success: result => {
          if (result.confirm) {
            wx.navigateTo({
              url: "/pages/wash/wash"
            });
          }
        }
      });
    } else {
      this.loadingDeiveInfo();
    }
  },

  async loadingDeiveInfo() {
    let did = "B220001";
    const token = wx.getStorageSync("token");
    const result = await http.req({
      url: api.WxWash,
      method: "POST",
      data: {
        did
      }
    });

    const { washer } = result;
    let washertype = {
      washertype_info: "",
      kgnum: ""
    };

    if (washer) {
      let arr = washer.washertype_info.split(" ");
      washertype["washertype_info"] = arr[0] + arr[1];
      washertype["kgnum"] = arr[2];
      washer.washertype = washertype;
    }
    this.setData({
      order: result
    });
  }
});
